home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 19 / Amiga Plus Leser CD 19.iso / Tools / Freeware / Swf_Player / Lib / shape.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-11-17  |  4.2 KB  |  182 lines

  1. /////////////////////////////////////////////////////////////
  2. // Flash Plugin and Player
  3. // Copyright (C) 1998,1999 Olivier Debon
  4. // 
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9. // 
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. // GNU General Public License for more details.
  14. // 
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  18. // 
  19. ///////////////////////////////////////////////////////////////
  20. #ifndef _SHAPE_H_
  21. #define _SHAPE_H_
  22.  
  23. struct LineStyleDef {
  24.     long         width;
  25.     Color         color;
  26.     FillStyleDef         fillstyle;
  27. };
  28.  
  29. enum ShapeRecordType {
  30.     shapeNonEdge,
  31.     shapeCurve,
  32.     shapeLine
  33. };
  34.  
  35. enum ShapeFlags {
  36.     flagsMoveTo       = 0x01,
  37.     flagsFill0       = 0x02,
  38.     flagsFill1       = 0x04,
  39.     flagsLine       = 0x08,
  40.     flagsNewStyles       = 0x10,
  41.     flagsEndShape        = 0x80
  42. };
  43.  
  44. struct ShapeRecord {
  45.     ShapeRecordType  type;
  46.  
  47.     // Non Edge
  48.     ShapeFlags     flags;
  49.     long         x,y;    // Moveto
  50.     long         fillStyle0;
  51.     long         fillStyle1;
  52.     long         lineStyle;
  53.     FillStyleDef    *newFillStyles; // Array
  54.     long         nbNewFillStyles;
  55.     LineStyleDef    *newLineStyles; // Array
  56.     long         nbNewLineStyles;
  57.  
  58.     // Curve Edge
  59.     long         ctrlX, ctrlY;
  60.     long         anchorX, anchorY;
  61.  
  62.     // Straight Line
  63.     long         dX,dY;
  64.  
  65.     struct ShapeRecord *next;
  66.  
  67.     ShapeRecord() {
  68.         shaperecord_size += sizeof(ShapeRecord);
  69.         shaperecord_nb++;
  70.     }
  71.  
  72. };
  73.  
  74. enum ShapeAction {
  75.     ShapeDraw,
  76.     ShapeGetRegion
  77. };
  78.  
  79. struct LineSegment {
  80.     long x1,y1,x2,y2;
  81.     char first;
  82.     LineStyleDef *l;
  83.     struct LineSegment *next;
  84. };
  85.  
  86. struct Path {
  87.     long lastX,lastY;
  88.     int nb_edges;
  89.     int nb_segments;
  90. };
  91.  
  92. struct StyleList {
  93.     FillStyleDef    *newFillStyles; // Array
  94.     long         nbNewFillStyles;
  95.     LineStyleDef    *newLineStyles; // Array
  96.     long         nbNewLineStyles;
  97.     
  98.     StyleList *next;
  99. };
  100.  
  101.  
  102. /* fast bit parser */
  103. struct BitParser {
  104.     // Bit Handling
  105.     S32 m_bitPos;
  106.     U32 m_bitBuf;
  107.  
  108.     U8 *ptr;
  109. };
  110.  
  111. class Shape;
  112.  
  113. /* state of the shape parser */
  114. struct ShapeParser {
  115.     Dict *dict;         /* XXX: should be put elsewhere */
  116.  
  117.     BitParser bit_parser;
  118.     S32 m_nFillBits;
  119.     S32 m_nLineBits;
  120.  
  121.     StyleList *style_list;
  122.     Matrix *matrix;
  123.     Path curPath;
  124.     int reverse;
  125.  
  126.     /* line rasteriser */
  127.     LineSegment *first_line,*last_line;
  128.     GraphicDevice *gd;
  129.     Cxform *cxform;
  130.     Shape *shape;
  131.  
  132.     FillStyleDef *f0;
  133.     FillStyleDef *f1;
  134.     LineStyleDef *l;
  135. };
  136.  
  137. class Shape : public Character {
  138.  public:
  139.     int         defLevel; // 1,2 or 3
  140.         
  141.  
  142.     Rect         boundary;
  143.     FillStyleDef     defaultFillStyle;
  144.     LineStyleDef     defaultLineStyle;
  145.  
  146.     Matrix         lastMat;
  147.         /* parsing for the rendering stage (saves a lot of memory &
  148.            may not reduce significantly the size). These variables
  149.            should be in another structure (no state need to be
  150.            maintained between two renderings) */
  151.         int getAlpha, getStyles;
  152.         unsigned char *file_ptr;
  153.         Dict *dict;         /* XXX: should be put elsewhere */
  154.  
  155. protected:
  156.     void     drawLines(GraphicDevice *gd, Matrix *matrix, Cxform *cxform, long, long);
  157.     void     buildSegmentList(Segment **segs, int height, long &n, Matrix *matrix, int update, int reverse);
  158.     Segment *progressSegments(Segment *, long);
  159.     Segment *newSegments(Segment *, Segment *);
  160.  
  161. public:
  162.     Shape(long id = 0 , int level = 1);
  163.     ~Shape();
  164.  
  165.     void     setBoundingBox(Rect rect);
  166.     int     execute(GraphicDevice *gd, Matrix *matrix, Cxform *cxform);
  167.     void     getRegion(GraphicDevice *gd, Matrix *matrix, 
  168.                            void *id, ScanLineFunc scan_line_func);
  169.  
  170.     void     getBoundingBox(Rect *bb, DisplayListEntry *);
  171.  
  172. #ifdef DUMP
  173.     void     dump(BitStream *bs);
  174.     void     dumpShapeRecords(BitStream *bs, int alpha);
  175.     void     dumpFillStyles(BitStream *bs, FillStyleDef *defs, long n, int alpha);
  176.     void     dumpLineStyles(BitStream *bs, LineStyleDef *defs, long n, int alpha);
  177.     void     checkBitmaps(BitStream *bs);
  178. #endif
  179. };
  180.  
  181. #endif /* _SHAPE_H_ */
  182.